<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri='http://java.sun.com/jsp/jstl/core' prefix='c'%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>View photo</title>
</head>
<body>

<c:if test="${ not empty sessionScope.user }">
	<a href="./LogoutController">Log out</a> <br/>
	<a href="./editUser.jsp">Edit personal information</a> <br/>
</c:if>
<c:if test="${ empty sessionScope.user }">
	<a href="./login.jsp">Log in</a> <br>
	<a href="./register.jsp">Register</a><br/>
</c:if>

<a href="./HomeController">Home</a> <br/>

<img alt="Greška, nema slike." src="${ requestScope.photo.location }">

<!--  rating  -->
<c:if test="${ requestScope.rated == false }">
	<c:if test="${ not empty sessionScope.user }">
		<c:if test="${ requestScope.photoOwner.id ne sessionScope.user.id }">
			<form action="./RatePhotoController" method="post">
				<input type="hidden" name="photoId" value="${ photo.id }">
				Rate photo: 1<input type="range" name="points" min="1" max="5">5
				<input type="submit">
			</form>
		</c:if>
	</c:if>
</c:if>

<c:if test="${ requestScope.rated == true }">
<br /> Your rate: <c:out value="${ requestScope.rate }" />
</c:if>
	

<!--  add to/remove from  favorites -->
<c:if test="${ not empty sessionScope.user }">
	<c:if test="${ requestScope.photoOwner.id ne sessionScope.user.id }">	
		<c:if test="${ not favouritePhoto }">
			<br />
			<a href="./AddFavoritePhotoController?photoId=${ photo.id }">Add photo to favorites</a>
		</c:if>
		
		<c:if test="${ favouritePhoto }">
			<br />
			<a href="./RemoveFavoritePhotoController?photoId=${ photo.id }">Remove photo from favorites</a>
		</c:if>
	</c:if>
</c:if>


<table>
	<c:if test="${ requestScope.photoOwner.id eq sessionScope.user.id }">
		<tr>
			<td>
				<a href="./PreEditPhotoController?id=${ requestScope.photo.id }">Edit photo settings</a> <br>
				<a href="./DeletePhotoController?id=${ requestScope.photo.id }">Delete this photo</a> <br>
			</td>
		</tr>
	</c:if>
	<tr>
		<td>Photo information:</td>
	</tr>
	<tr>
		<td>Owner</td>
		<td>
			<a href="./ViewUserController?id=${ requestScope.photoOwner.id }">
				${ requestScope.photoOwner.firstname } ${ requestScope.photoOwner.lastname }
			</a>
		</td>
	</tr>
	<tr>
		<td>Title</td>
		<td>${ requestScope.photo.title }</td>
	</tr>
	<tr>
		<td>Description</td>
		<td>${ requestScope.photo.description }</td>
	</tr>
	<tr>
		<td>Width</td>
		<td>${ requestScope.photo.width }</td>
	</tr>
	<tr>
		<td>Height</td>
		<td>${ requestScope.photo.height }</td>
	</tr>
	<tr>
		<td>Size</td>
		<td>${ requestScope.photo.size }</td>
	</tr>
	<tr>
		<td>Upload date</td>
		<td>${ requestScope.photo.uploadDate }</td>
	</tr>
	<tr>
		<td>Publicly available</td>
		<td>${ requestScope.photo.publiclyAvailable}</td>
	</tr>
	<tr>
		<td>Tags allowed</td>
		<td>${ requestScope.photo.tagsAllowed}</td>
	</tr>
	<tr>
		<td>Notes allowed</td>
		<td>${ requestScope.photo.notesAllowed}</td>
	</tr>
	<tr>
		<td>Comments allowed</td>
		<td>${ requestScope.photo.commentsAllowed}</td>
	</tr>
	<tr>
		<td>Average rating</td>
		<td>${ requestScope.photo.averageRating }</td>
	</tr>
	

	
	
	<!-- ratings -->
	<tr>
		<td>Ratings by users</td>
	</tr>
	<c:if test="${ empty requestScope.photo.ratings }">
		<tr>
			<td>
				<c:out value="No ratings yet"></c:out>
			<td>
		</tr>
	</c:if>
	<c:if test="${ not empty requestScope.photo.ratings }">
		<c:forEach var="currentRating" items="${ requestScope.photo.ratings }" varStatus="status">
			<tr>
				<td>
					<c:out value="${ status.count }."></c:out>	
					<a href="./ViewUserController?id=${ currentRating.userThatRated.id }">
						<c:out value="${ currentRating.userThatRated.firstname } ${ currentRating.userThatRated.lastname }"></c:out>
					</a>
					<c:out value=" - ${ currentRating.vote }"></c:out>
				</td>
			</tr>
			<c:if test="${ status.last }">
				<tr>
					<td>
						<br/>
					</td>
				</tr>
			</c:if>
		</c:forEach>
	</c:if>
	
	
	
	<!-- comments -->
	<tr>
		<td>Comments</td>
	</tr>
	<c:if test="${ empty requestScope.photo.comments }">
		<tr>
			<td>
				<c:out value="No comments yet"></c:out>
			<td>
		</tr>
	</c:if>
	<c:if test="${ not empty requestScope.photo.comments }">
		<c:forEach var="currentComment" items="${ requestScope.photo.comments }" varStatus="status">
			<tr>
				<td>
					<c:out value="${ status.count }."></c:out>
					<a href="./ViewUserController?id=${ currentComment.user.id }">
					<c:out value="${ currentComment.user.firstname } ${ currentComment.user.lastname }"></c:out>
					</a>
					<c:out value=" - ${ currentComment.date }"></c:out>
					<br/>
					<c:out value="${ currentComment.title } - ${ currentComment.contents }"></c:out>
					<c:if test="${ requestScope.photoOwner.id eq sessionScope.user.id or currentComment.user.id eq  sessionScope.user.id }">
						<a href="./DeleteCommentController?photoId=${ requestScope.photo.id }&commentId=${ currentComment.id }">
							<input type="button" value="Delete">
						</a>
					</c:if>
				</td>
			</tr>
			<c:if test="${ status.last }">
				<tr>
					<td>
						<br/>
					</td>
				</tr>
			</c:if>
		</c:forEach>
	</c:if>
	
	
	<c:if test="${ photo.commentsAllowed and not empty sessionScope.user }">
		<tr>
			<td>
				<form name="input" action="./PostCommentController" method="post">
					<input type="hidden" name="photoId" value="${ photo.id }">
					<label>Naslov komentara: </label> <input type="text" name="commentTitle"> <br />
					<textarea name="commentText" rows="3" cols="50"  placeholder="Insert comment here"></textarea>
					<input type="submit" value="Post comment">
				</form>
			</td>
		</tr>
	</c:if>
	
	
	
	<!--  tags  -->
	<tr>
		<td>Tags: </td>
		<c:if test="${ empty requestScope.photo.tags }">
			<tr>
				<td>
					<c:out value="No tags yet"></c:out>
				<td>
			</tr>
		</c:if>
		<c:if test="${ not empty requestScope.photo.tags }">
			<c:forEach var="currentTag" items="${ requestScope.photo.tags }" varStatus="status">
				<tr>
					<td>
						<br/>
						<c:out value="${ currentTag.text }" />
						<c:if test="${ requestScope.photoOwner.id eq sessionScope.user.id }">
							<a href="./DeleteTagController?photoId=${ requestScope.photo.id }&tagId=${ currentTag.id }">
								<input type="button" value="Delete">
							</a>
						</c:if>
					</td>
				</tr>
				<c:if test="${ status.last }">
					<tr>
						<td>
							<br/>
						</td>
					</tr>
				</c:if>
			</c:forEach>
		</c:if>
	</tr>
	
	<c:if test="${ photo.tagsAllowed and not empty sessionScope.user }">
		<tr>
			<td>
				<form name="input" action="./TagPhotoController" method="post">
					<input type="hidden" name="photoId" value="${ photo.id }">
					<label>Add tag: </label> <input type="text" name="tagtext"> 
					<input type="submit" value="Post tag">
				</form>
			</td>
		</tr>
	</c:if>


</table>

</body>
</html>